package com.ssh;

import org.junit.Test;

public class ValidPalindrome_680 {
	@Test
	public void test() {
		
		System.out.println(validPalindrome("asta"));
	}
	
	public boolean validPalindrome(String s) {
        int lo = 0,hi = s.length()-1;
        boolean t = true;
        while (lo <= hi) {
        	if (s.charAt(lo) != s.charAt(hi)) {
        		if (hi == lo+1 && t)
        			return true;
        		else if (t) {
        			t = false;
        			if (s.charAt(lo+1) == s.charAt(hi) && s.charAt(lo+2) == s.charAt(hi-1)) {
        				lo++;
        			}else if (s.charAt(lo) == s.charAt(hi-1) && s.charAt(lo+1) == s.charAt(hi-2)) {
        				hi--;
        			}else {
        				return false;
        			}
        		}else {
        			return false;
        		}
        	}
        	lo++;
        	hi--;
        }
        return true;
    }
}
